#include <iostream>
#include <string>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  string raw_seq, seq;
  bool bflag = false;
  cout << "Enter sequence:\n";
  cin >> raw_seq;
  for (char &c : raw_seq)
  if (c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '<' || c == '>')
    seq.append(1, c);
  stack<char> st;
  for (char c : seq) {
    switch (c) {
      case '(':
        st.push(c);
        break;
      case ')':
        if (st.empty() || st.top() != '(') {
            bflag = true;
            break;
        }
        st.pop();
        break;
      case '[':
        st.push(c);
        break;
      case ']':
        if (st.empty() || st.top() != '[') {
            bflag = true;
            break;
        }
        st.pop();
        break;
      case '{':
        st.push(c);
        break;
      case '}':
        if (st.empty() || st.top() != '{') {
            bflag = true;
            break;
        }
        st.pop();
        break;
      case '<':
        st.push(c);
        break;
      case '>':
        if (st.empty() || st.top() != '<') {
            bflag = true;
            break;
        }
        st.pop();
        break;
    }
    if (bflag)
        break;
  }
  if (st.empty() && !bflag)
    cout << "True" << endl;
  else
    cout << "False" << endl;
}
